In [5]:
%load_ext autoreload
%matplotlib nbagg
%autoreload 2
import copy
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl
Lien vers data.gouv.fr : https://www.data.gouv.fr/fr/datasets/base-de-donnees-accidents-corporels-de-la-circulation/#_
Documentation de la base de donnée : DATA/Description_des_bases_de_donneesONISR-Annees_2005_a_2016.pdf
In [66]:
dfc = pd.read_csv('./DATA/caracteristiques_2016.csv')
dfu = pd.read_csv('./DATA/usagers_2016.csv')
dfl = pd.read_csv('./DATA/lieux_2016.csv')
df = pd.concat([dfu, dfc, dfl], axis=1)
In [71]:
dfc.tail()
Out[71]:
In [65]:
dfu.head()
Out[65]:
In [70]:
dfl.tail()
Out[70]:
In [68]:
df.head()
Out[68]:
In [63]:
df = pd.concat([df, dfl], axis=1)
df.head()
Out[63]:
In [33]:
# methode pas propre
(h,c)=df[df.sexe==1].shape
(f,c)=df[df.sexe==2].shape
(t,c)=df.shape
print('h/t=', h/t)
print('f/t=', f/t)
In [34]:
# methode panda
df["sexe"].value_counts(normalize=True)
Out[34]:
In [55]:
fig = plt.figure()
df[df.grav==2].sexe.value_counts(normalize=True).plot.pie(labels=['Homme', 'Femme'], colors= ['r', 'g'], autopct='%.2f')
Out[55]:
In [46]:
dlum = df["lum"].value_counts(normalize=True)
dlum = dlum.sort_index()
In [47]:
dlum
Out[47]:
In [57]:
dlum[3] = dlum[3:5].sum()
fig = plt.figure()
dlum[1:3].plot.pie(labels=['Jour','Aube/crépuscule', 'Nuit'], colors= ['y', 'g' , 'b'], autopct='%.2f')
Out[57]:
In [109]:
df.lat=df.lat/100000
df.long=df.long/100000
dfp = df[df.gps=='M']
dfp = dfp[['lat','long']]
dfp = dfp[(dfp.long!=0.0) & (dfp.lat!=0.0)]
dfp.head()
Out[109]:
In [110]:
#fig = plt.figure()
dfp.plot.scatter(x='long', y='lat',s=1);
In [111]:
df[(df.long!=0.0) & (df.lat!=0.0) & (df.gps=='M')].plot.scatter(x='long', y='lat',s=.5);
In [ ]: